package com.ruoyi.web.controller.production.stroma;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.production.domain.stroma.StromaKind;
import com.ruoyi.production.service.stroma.IStromaKindService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 基质种Controller
 *
 * @author ruoyi
 * @date 2021-07-12
 */
@RestController
@RequestMapping("/production/stromaKind")
public class StromaKindController extends BaseController
{
    @Autowired
    private IStromaKindService stromaKindService;

    /**
     * 查询基质种列表
     */
    @PreAuthorize("@ss.hasPermi('production:stromaKind:list')")
    @GetMapping("/list")
    public TableDataInfo list(StromaKind stromaKind)
    {
        startPage();
        List<StromaKind> list = stromaKindService.selectStromaKindList(stromaKind);
        return getDataTable(list);
    }

    /**
     * 导出基质种列表
     */
    @PreAuthorize("@ss.hasPermi('production:stromaKind:export')")
    @Log(title = "基质种", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(StromaKind stromaKind)
    {
        List<StromaKind> list = stromaKindService.selectStromaKindList(stromaKind);
        ExcelUtil<StromaKind> util = new ExcelUtil<StromaKind>(StromaKind.class);
        return util.exportExcel(list, "基质种数据");
    }

    /**
     * 获取基质种详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:stromaKind:query')")
    @GetMapping(value = "/{stromaKindId}")
    public AjaxResult getInfo(@PathVariable("stromaKindId") Long stromaKindId)
    {
        return AjaxResult.success(stromaKindService.selectStromaKindById(stromaKindId));
    }

    /**
     * 新增基质种
     */
    @PreAuthorize("@ss.hasPermi('production:stromaKind:add')")
    @Log(title = "基质种", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StromaKind stromaKind)
    {
        return toAjax(stromaKindService.insertStromaKind(stromaKind));
    }

    /**
     * 修改基质种
     */
    @PreAuthorize("@ss.hasPermi('production:stromaKind:edit')")
    @Log(title = "基质种", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StromaKind stromaKind)
    {
        return toAjax(stromaKindService.updateStromaKind(stromaKind));
    }

    /**
     * 删除基质种
     */
    @PreAuthorize("@ss.hasPermi('production:stromaKind:remove')")
    @Log(title = "基质种", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stromaKindIds}")
    public AjaxResult remove(@PathVariable Long[] stromaKindIds)
    {
        return toAjax(stromaKindService.deleteStromaKindByIds(stromaKindIds));
    }
}
